import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../layout' //布局页

Vue.use(VueRouter)
//解决重复点击左侧菜单的报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


export const asyncRoutes = [
  {
    path: '/config',
    component: Layout,
    meta: {
      title: "小程序管理",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        path: '/banner',
        name: 'banner',
        component: () => import('@/views/banner/index.vue'),
        meta: {
          title: "轮播管理",
        }
      },
      {
        path: '/news',
        name: 'news',
        component: () => import('@/views/news/index.vue'),
        meta: {
          title: "资讯管理",
        }
      },
      {
        path: '/course',
        name: 'course',
        component: () => import('@/views/course/index.vue'),
        meta: {
          title: "课程管理",
        }
      },
      {
        path: '/sign',
        name: 'sign',
        component: () => import('@/views/sign/index.vue'),
        meta: {
          title: "报名管理",
        }
      },
      {
        path: '/policy',
        name: 'policy',
        component: () => import('@/views/system/policy/index.vue'),
        meta: {
          title: "协议配置",
        }
      },
    ]
  },
  {
    path: '/',
    component: Layout,
    meta: {
      title: "用户管理",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        path: '/parent',
        name: 'parent',
        component: () => import('@/views/parent/index.vue'),
        meta: {
          title: "家长管理",
        }
      },
      {
        path: '/student',
        name: 'student',
        component: () => import('@/views/student/index.vue'),
        meta: {
          title: "学生管理",
        }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    meta: {
      title: "系统管理",
      icon: 'el-icon-s-custom',
    },
    name: 'system',
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/system/user/index.vue'),
        meta: {
          title: "教师管理",
        }
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/views/system/role/index.vue'),
        meta: {
          title: "角色管理",
        }
      },
      {
        path: 'menu',
        name: 'menu',
        component: () => import('@/views/system/menu/index.vue'),
        meta: {
          title: "菜单管理",
        }
      },
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/login'),
    meta: {
      title: "欢迎登录",
    },
    hidden: true //导航菜单忽略选项
  },
]


const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: asyncRoutes
})

export default router
